package com.neiru.divider.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.TextView;

import com.neiru.divider.R;
import com.neiru.divider.bean.Level;
import com.neiru.divider.constants.ActivityConstants;

public class LevelComplete extends Activity {
	private Level level = null;
	private Long score = null;
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if(savedInstanceState != null) {
			this.level = (Level)savedInstanceState.getSerializable(ActivityConstants.PLAY_LEVEL_DATA_NAME);
			this.score = (Long) savedInstanceState.getLong(ActivityConstants.PLAY_LEVEL_DATA_SCORE);
		}
		if(this.score == null && getIntent().getExtras() != null) {
			this.score= (Long)getIntent().getExtras().getLong(ActivityConstants.PLAY_LEVEL_DATA_SCORE);
		}
		if(this.level == null && getIntent().getExtras() != null) {
			this.level = (Level)getIntent().getExtras().getSerializable(ActivityConstants.PLAY_LEVEL_DATA_NAME);
		}
		
		requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.level_complete); 
		configureButtons();
	}
	
	private void configureButtons() {
		TextView levelTextView = (TextView)findViewById(R.id.level);
		levelTextView.setText(""+this.level.getLevel());
		TextView scoreTextView = (TextView)findViewById(R.id.score);
		scoreTextView.setText(""+this.score);
		ImageButton nextLevel = (ImageButton)findViewById(R.id.nextLevel);
		nextLevel.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				LevelComplete.this.setResult(ActivityConstants.PLAY_RESULT_NEXT_LEVEL);
				LevelComplete.this.finish();
			}
		});
		
		ImageButton exit = (ImageButton)findViewById(R.id.exit);
		exit.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				LevelComplete.this.setResult(ActivityConstants.PLAY_RESULT_FINISH);
				LevelComplete.this.finish();
			}
		});
	}
	@Override
	protected void onPause() {
		super.onPause();
		this.finish();
	}
}
